package list

func swapPairs(head *ListNode) *ListNode {

	if head == nil {
		return nil
	}

	dummyHead := &ListNode{
		Val:  -1,
		Next: head,
	}

	temp := dummyHead

	for temp != nil && temp.Next != nil && temp.Next.Next != nil {

		tail := temp.Next.Next
		next := tail.Next

		temp.Next, tail.Next, temp.Next.Next = tail, temp.Next, next
		temp = temp.Next.Next
	}

	return dummyHead.Next

}
